package com.ruoyi.web.controller.user;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.entity.AppUser;
import com.ruoyi.common.core.domain.vo.AppUserVO;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.user.service.IAppUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;

import java.util.List;

/**
 * 用户信息Controller
 *
 * @author ghostmen
 * @date 2024-11-02
 */
@Validated
@Api(value = "用户管理", tags = "用户管理接口")
@RestController
@RequestMapping("/appUser")
public class UserController extends BaseController {

    @Autowired
    private IAppUserService appUserService;

    /**
     * 查询用户信息列表
     */
    @ApiOperation(value = "查询用户信息列表")
    @PreAuthorize("@ss.hasPermi('app:user:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppUser appUser) {
        startPage();
        List<AppUserVO> list = appUserService.selectAppUserList(appUser);
        return getDataTable(list);
    }

    /**
     * 获取用户信息详细信息
     */
    @ApiOperation(value = "获取用户信息详细信息")
    @PreAuthorize("@ss.hasPermi('app:user:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@ApiParam(value = "用户Id", required = true) @PathVariable("userId") Long userId) {
        return success(appUserService.selectAppUserByUserId(userId));
    }


    /**
     * 修改用户账号状态
     */
    @ApiOperation(value = "修改用户账号状态")
    @GetMapping(value = "/updateStatusByUserId")
    @PreAuthorize("@ss.hasPermi('app:user:updateStatusByUserId')")
    @Log(title = "修改用户账号状态", businessType = BusinessType.UPDATE)
    public AjaxResult updateStatusByUserId(@ApiParam(value = "用户Id", required = true) @RequestParam Long userId,
                                           @ApiParam(value = "帐号状态（0正常 1停用）", required = true) @RequestParam Integer status) {
        return success(appUserService.updateStatusByUserId(userId, status));
    }

}
